package com.hichina.client;

import com.hichina.client.util.ResponseUtils;
import com.hichina.exception.HiChinaException;
import com.hichina.exception.InvalidTokenException;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by IntelliJ IDEA.
 * User: zigang.wang
 * Date: 12-3-1
 * Time: 上午10:00
 * To change this template use File | Settings | File Templates.
 */
public class Account {
    private String name;//账号姓名
    private String uid;//完整账号
    private String employeeNo;//员工编号
    private String departId;//部门ID
    private int userRole;//帐号权限（0：管理帐号 1：普通帐号）
    private String status;// 0:已购买，1：试用, 2 开发者测试
    private String email;
    private String  post;//职位信息

    public Account() {
    }

    public Account(String jsonContent) throws InvalidTokenException, HiChinaException {
            this(ResponseUtils.checkResponse(jsonContent));
    }

    public Account(JSONObject json) throws HiChinaException {
        try {
            setName(json.getString("name"));
            setUid(json.getString("uid"));
            setEmployeeNo(json.getString("employeeNo"));
            setDepartId(json.getString("departmentId"));
            setUserRole(json.getInt("userRole"));
            if(json.has("post")){
              setPost(json.getString("post"));
            }
            if(json.has("status")){
                setStatus(json.getString("status"));
            }
            if(json.has("email")){
                setEmail(json.getString("email"));
            }
        } catch (JSONException e) {
            throw new HiChinaException(json.toString() + " can not conver to JSONObject");
        }
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getEmployeeNo() {
        return employeeNo;
    }

    public void setEmployeeNo(String employeeNo) {
        this.employeeNo = employeeNo;
    }

    public String getDepartId() {
        return departId;
    }

    public void setDepartId(String departId) {
        this.departId = departId;
    }

    public int getUserRole() {
        return userRole;
    }

    public void setUserRole(int userRole) {
        this.userRole = userRole;
    }

    @Override
    public String toString() {
        return "Account{" +
                "name='" + name + '\'' +
                ", uid='" + uid + '\'' +
                ", employeeNo='" + employeeNo + '\'' +
                ", departId='" + departId + '\'' +
                ", userRole=" + userRole +
                ", status='" + status + '\'' +
                ", email='" + email + '\'' +
                '}';
    }
}
